<template>
  <div class="search-box">
    <i class="icon-search mui-icon mui-icon-arrowleft"></i>
    <input class="box" ref="query" :placeholder="placeholder" v-model="query">
    <i @click="clear" class="icon-dismiss mui-icon mui-icon-closeempty" v-show="query"></i>
  </div>
</template>

<script type="text/javascript">
import { debounce } from '@/common/js/util'

export default {
  props: {
    placeholder: {
      type: String,
      default: '搜索歌曲， 歌手'
    }
  },
  data () {
    return {
      query: ''
    }
  },
  methods: {
    clear () {
      this.query = ''
    },
    setQuery (query) {
      this.query = query.first
    },
    blur () {
      this.$refs.query.blur()
    }
  },
  created () {
    this.$watch('query', debounce((newQuery) => {
      this.$emit('query', newQuery)
    }, 200))
  }
}
</script>

<style lang="less" scoped>
@import "~@/common/stylus/variable";

.search-box {
  // position: relative;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  width: 100%;
  height: 25px;
  /*border-bottom: 1px solid rgb(235, 235, 235);*/
  padding-top: 7px;
  .icon-search {
    font-size: 24px;
    color: @color-text-g;
  }
  .box {
    flex: 1;
    line-height: 25px;
    background: @color-theme;
    color: #fff;
    font-size: @font-size-medium;
    border: none;
    outline: medium;
    border-radius: 5px;
    padding-left: 12px;
    &::placeholder {
      color: rgba(255, 255, 255, 0.6);
    }
  }
  .icon-delete {
    position: absolute;
    right: 12px;
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
    border: none;
  }
  .search {
    padding: 0 5px;
    font-size: 14px;
    color: @color-text;
  }
}
</style>
